// src/scenarios/energy_management.rs

//! 能源管理场景
//! 支持能源管理的语义转换和OPC UA模型构建

use crate::scenarios::*;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;

/// 能源管理场景
pub struct EnergyManagementScenario {
    config: ScenarioConfig,
}

impl EnergyManagementScenario {
    pub fn new() -> Self {
        Self {
            config: ScenarioConfig {
                name: Some("能源管理语义转换场景".to_string()),
                description: Some("支持能源管理数据的语义转换和OPC UA模型构建，包括电力监控、能耗分析、智能电网等".to_string()),
                custom_rules: None,
                extensions: HashMap::new(),
            },
        }
    }

    pub fn new_with_config(config: ScenarioConfig) -> Self {
        Self { config }
    }
}

impl Scenario for EnergyManagementScenario {
    fn name(&self) -> &'static str {
        "Energy Management Semantic Conversion"
    }

    fn description(&self) -> &'static str {
        "能源管理语义转换场景，支持能源管理数据的语义转换"
    }

    fn industry(&self) -> &'static str {
        "EnergyManagement"
    }

    fn get_transformation_rules(&self) -> ScenarioTransformationRules {
        ScenarioTransformationRules {
            rule_name: "Energy_Management_General".to_string(),
            data_source_mappings: HashMap::new(),
            unit_conversions: HashMap::new(),
            data_type_mappings: HashMap::new(),
            semantic_mappings: HashMap::new(),
            constraints: vec![],
        }
    }

    fn get_opcua_model_template(&self) -> ScenarioModelTemplate {
        ScenarioModelTemplate {
            template_name: "EnergyManagementModel".to_string(),
            namespaces: vec![
                "http://opcfoundation.org/UA/".to_string(),
                "http://industryagent.com/energy/".to_string(),
            ],
            object_types: vec![],
            variable_types: vec![],
            reference_types: vec![],
        }
    }

    fn get_sample_data(&self) -> Vec<ScenarioSampleData> {
        vec![
            ScenarioSampleData {
                data_id: "energy_meter_001".to_string(),
                data_source_type: "HuaweiCloudIoT".to_string(),
                raw_data: serde_json::json!({
                    "meter_id": "EM-001",
                    "location": "配电房",
                    "voltage": 380.5,
                    "current": 125.3,
                    "power": 47.8,
                    "energy_consumption": 1024.5,
                    "timestamp": "2024-01-15T10:30:00Z"
                }),
                expected_opcua: serde_json::json!({"nodeId": "ns=7;i=1001"}),
                description: Some("能源计量数据示例".to_string()),
                category: Some("PowerMonitoring".to_string()),
            },
        ]
    }

    fn get_semantic_mappings(&self) -> HashMap<String, String> {
        let mut mappings = HashMap::new();
        mappings.insert("energy_meter".to_string(), "EnergyMeter".to_string());
        mappings.insert("power_sensor".to_string(), "PowerSensor".to_string());
        mappings
    }
}